<%-- 
    Document   : blog
    Created on : 2010-7-3, 18:29:49
    Author     : reyesyang
    JQuery     : jquery-1.4.2
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@ page isELIgnored="false" %>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Reyes Yang's Utopia - Blog</title>
        <script type="text/javascript" src="/resource/script/jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="/resource/script/blog.js"></script>
        <script language="javascript" type="text/javascript" src="/resource/script/global.js"></script>
        <link rel="stylesheet" type="text/css" href="/resource/style/global.css"/>
    </head>
    <body>
        <div id="header">
            <jsp:include page="/page/global/header.jsp"/>
        </div>
        <div id="nav">
            <jsp:include page="/page/global/navigation.jsp" />
        </div>
        <div id="content">
            <div id="main">
                <logic:equal value="all" name="scope">
                    <em id="page-title">Blog</em>
                </logic:equal>
                <logic:notEqual value="all" name="scope">
                    <em id="page-title">Blog of ${scope}: ${condition}</em>
                </logic:notEqual>
                <logic:empty name="blogs" scope="request">
                    <b>No blog was posted now!</b>
                </logic:empty>
                <logic:notEmpty name="blogs" scope="request">
                    <logic:iterate id="blog" name="blogs">
                        <div class="blog" id="${blog.nickTitle}">
                            <div class="mainInfo">
                                <h2>
                                    <html:link href="/blog/${blog.nickTitle}">
                                        <bean:write name="blog" property="title"/>
                                    </html:link>
                                </h2>
                                <p><bean:write name="blog" property="summary" filter="false"/></p>
                                <p class="readMore">
                                    <a href="/blog/${blog.nickTitle}">Read More</a>
                                </p>
                            </div>
                            <div class="extendInfo">
                                <p>
                                    <em>Post Date: </em>
                                    <em><bean:write name="blog" property="date" format="yyyy-MM-dd HH:mm:ss"/></em>
                                </p>
                                <p>
                                    <em>Category:</em>
                                    <em>
                                        <a href="/blog/category/${blog.category}/1" title="Display all blogs in ${blog.category}">
                                            <bean:write name="blog" property="category"/>
                                        </a>
                                    </em>
                                </p>
                                <div class="blogOperate">
                                    <ul class="blogOperate">
                                        <li>
                                            <a href="/blog/${blog.nickTitle}">
                                                <em>Read(${blog.readCount})</em>
                                            </a>
                                        </li>
                                        <li class="firstOperate">
                                            <a href="/blog/${blog.nickTitle}/blogComment" title="Read more comment">
                                                <em>Comment(${blog.commentCount})</em>
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </logic:iterate>
                    <ul id="pageNav">
                        <li>Page ${page}/${pageCount}</li>
                        <%
                                    int currentPage = (Integer) request.getAttribute("page");
                                    int pageCount = (Integer) request.getAttribute("pageCount");
                                    String scope = (String) request.getAttribute("scope");
                                    String condition = (String) request.getAttribute("condition");
                                    if (pageCount <= 5) {
                                        if (currentPage == pageCount || (currentPage != 1 && currentPage != pageCount)) {
                                            if (scope.equals("all")) {
                                                out.print("<li>"
                                                        + "<a href='/blog/all/1'>"
                                                        + "<<"
                                                        + "</a>"
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "<a href='/blog/all/" + (currentPage - 1) + "'>"
                                                        + "<"
                                                        + "</a>"
                                                        + "</li>");
                                            } else {
                                                out.print("<li>"
                                                        + "<a href='/blog/" + scope + "/" + condition + "/1'>"
                                                        + "<<"
                                                        + "</a>"
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "<a href='/blog/" + scope + "/" + condition + "/" + (currentPage - 1) + "'>"
                                                        + "<"
                                                        + "</a>"
                                                        + "</li>");
                                            }
                                        }
                                        for (int index = 1; index <= pageCount; index++) {
                                            if (index == currentPage) {
                                                out.print("<li id='currentPage'>"
                                                        + "<a href='#'>" + index + "</a>"
                                                        + "</li>");
                                            } else {
                                                if (scope.equals("all")) {
                                                    out.print("<li>"
                                                            + "<a href='/blog/all/" + index + "'>" + index + "</a>"
                                                            + "</li>");
                                                } else {
                                                    out.print("<li>"
                                                            + "<a href='/blog/" + scope + "/" + condition + "/" + index + "'>" + index + "</a>"
                                                            + "</li>");
                                                }
                                            }
                                        }
                                        if (currentPage == 1 || (currentPage != 1 && currentPage != pageCount)) {
                                            if (scope.equals("all")) {
                                                out.print("<li>"
                                                        + "<a href='/blog/all/" + (currentPage + 1) + "'>"
                                                        + ">"
                                                        + "</a>"
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "<a href='/blog/all/" + pageCount + "'>"
                                                        + ">>"
                                                        + "</a>"
                                                        + "</li>");
                                            } else {
                                                out.print("<li>"
                                                        + "<a href='/blog/" + scope + "/" + condition + "/" + (currentPage + 1) + "'>"
                                                        + ">"
                                                        + "</a>"
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "<a href='/blog/" + scope + "/" + condition + "/" + pageCount + "'>"
                                                        + ">>"
                                                        + "</a>"
                                                        + "</li>");
                                            }
                                        }
                                    } else {
                                        if (currentPage < 3) {
                                            for (int index = 1; index <= 5; index++) {
                                                if (index == currentPage) {
                                                    out.print("<li id='currentPage'>"
                                                            + "<a href='#'>" + index + "</a>"
                                                            + "</li>");
                                                } else {
                                                    if (scope.equals("all")) {
                                                        out.print("<li>"
                                                                + "<a href='/blog/all/" + index + "'>" + index + "</a>"
                                                                + "</li>");
                                                    } else {
                                                        out.print("<li>"
                                                                + "<a href='/blog/" + scope + "/" + condition + "/" + index + "'>" + index + "</a>"
                                                                + "</li>");
                                                    }
                                                }
                                            }
                                            if (scope.equals("all")) {
                                                out.print("<li>"
                                                        + "<a href='/blog/all/" + (currentPage + 1) + "'>"
                                                        + ">"
                                                        + "</a>"
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "..."
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "<a href='/blog/all/" + pageCount + "'>"
                                                        + ">>"
                                                        + "</a>"
                                                        + "</li>");
                                            } else {
                                                out.print("<li>"
                                                        + "<a href='/blog/" + scope + "/" + condition + "/" + (currentPage + 1) + "'>"
                                                        + ">"
                                                        + "</a>"
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "..."
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "<a href='/blog/" + scope + "/" + condition + "/" + pageCount + "'>"
                                                        + ">>"
                                                        + "</a>"
                                                        + "</li>");
                                            }
                                        } else if (currentPage > 3 && currentPage <= pageCount - 3) {
                                            if (scope.equals("all")) {
                                                out.print("<li>"
                                                        + "<a href='/blog/all/1'>"
                                                        + "<<"
                                                        + "</a>"
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "..."
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "<a href='/blog/all/" + (currentPage - 1) + "'>"
                                                        + "<"
                                                        + "</a>"
                                                        + "</li>");
                                            } else {
                                                out.print("<li>"
                                                        + "<a href='/blog/" + scope + "/" + condition + "/1'>"
                                                        + "<<"
                                                        + "</a>"
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "..."
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "<a href='/blog/" + scope + "/" + condition + "/" + (currentPage - 1) + "'>"
                                                        + "<"
                                                        + "</a>"
                                                        + "</li>");
                                            }
                                            for (int index = currentPage - 2; index <= currentPage + 2; index++) {
                                                if (index == currentPage) {
                                                    out.print("<li id='currentPage'>"
                                                            + "<a href='#'>" + index + "</a>"
                                                            + "</li>");
                                                } else {
                                                    if (scope.equals("all")) {
                                                        out.print("<li>"
                                                                + "<a href='/blog/all/" + index + "'>" + index + "</a>"
                                                                + "</li>");
                                                    } else {
                                                        out.print("<li>"
                                                                + "<a href='/blog/" + scope + "/" + condition + "/" + index + "'>" + index + "</a>"
                                                                + "</li>");
                                                    }
                                                }
                                            }
                                            if (scope.equals("all")) {
                                                out.print("<li>"
                                                        + "<a href='/blog/all/" + (currentPage + 1) + "'>"
                                                        + ">"
                                                        + "</a>"
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "..."
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "<a href='/blog/all/" + pageCount + "'>"
                                                        + ">>"
                                                        + "</a>"
                                                        + "</li>");
                                            } else {
                                                out.print("<li>"
                                                        + "<a href='/blog/" + scope + "/" + condition + "/" + (currentPage + 1) + "'>"
                                                        + ">"
                                                        + "</a>"
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "..."
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "<a href='/blog/" + scope + "/" + condition + "/" + pageCount + "'>"
                                                        + ">>"
                                                        + "</a>"
                                                        + "</li>");
                                            }
                                        } else {
                                            if (scope.equals("all")) {
                                                out.print("<li>"
                                                        + "<a href='/blog/all/1'>"
                                                        + "<<"
                                                        + "</a>"
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "..."
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "<a href='/blog/all/" + (currentPage - 1) + "'>"
                                                        + "<"
                                                        + "</a>"
                                                        + "</li>");
                                            } else {
                                                out.print("<li>"
                                                        + "<a href='/blog/" + scope + "/" + condition + "/1'>"
                                                        + "<<"
                                                        + "</a>"
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "..."
                                                        + "</li>");
                                                out.print("<li>"
                                                        + "<a href='/blog/" + scope + "/" + condition + "/" + (currentPage + 1) + "'>"
                                                        + "<"
                                                        + "</a>"
                                                        + "</li>");
                                            }
                                            for (int index = pageCount - 4; index <= pageCount; index++) {
                                                if (index == currentPage) {
                                                    out.print("<li id='currentPage'>"
                                                            + "<a href='#'>" + index + "</a>"
                                                            + "</li>");
                                                } else {
                                                    if (scope.equals("all")) {
                                                        out.print("<li>"
                                                                + "<a href='/blog/all/" + index + "'>" + index + "</a>"
                                                                + "</li>");
                                                    } else {
                                                        out.print("<li>"
                                                                + "<a href='/blog/" + scope + "/" + condition + "/" + index + "'>" + index + "</a>"
                                                                + "</li>");
                                                    }
                                                }
                                            }
                                        }
                                    }


                        %>                     
                    </ul>
                </logic:notEmpty>
            </div>
            <div id="aside">
               <jsp:include page="/page/global/aside.jsp"/>
            </div>
        </div>
        <div id="footer"></div>
    </body>
</html>

